﻿ using UnityEngine;
using System.Collections;

public class ButtonEvents : MonoBehaviour {

	private MusicSound sound;
	private MusicSound music;
	private GameObject[]sounds,musics;
	private GameManager manager;

	private void Start(){
		sounds=new GameObject[]{GameObject.FindGameObjectWithTag("sound"),GameObject.FindGameObjectWithTag("no_sound")};
		musics=new GameObject[]{GameObject.FindGameObjectWithTag("music"),GameObject.FindGameObjectWithTag("no_music")};
		manager=GameManager.getInstance();
	}
	private void OnSound(){
        SoundCon.instance.PlaySound(1);
		manager.Sound=!manager.Sound;
		new Invoker(new MusicSound(sounds,manager.Sound)).Execute();
	}
	private void OnMusic(){
        SoundCon.instance.PlaySound(1);        
        StartCoroutine(loadNextScene());
        manager.Music=!manager.Music;
        new Invoker(new MusicSound(musics,manager.Music)).Execute();
        if (manager.Music)
        {
            MusicCon.instance.PlayMusic();
        }
        else { MusicCon.instance.StopMusic(); }
	}
	public void Play(){
        if (manager.ButtonClick == Click.can_click){
             manager.IsPlay = true;
          	manager.ButtonClick = Click.can_not_click;
            StartCoroutine(loadNextScene());
            new Invoker(new Play(2)).Execute();
            manager.IsShow = false;
         }
        else { Debug.Log(manager.ButtonClick); }
        SoundCon.instance.PlaySound(1);
        manager.ButtonClick = Click.can_click;
	}
    
    private void ConFacebook(){
        Debug.Log(manager.IsPlay);
        if (manager.IsPlay)
        { manager.ButtonClick = Click.can_not_click; }
        if (manager.ButtonClick == Click.can_click)
        { }
        else{
            Debug.Log(manager.ButtonClick);
        }
        Debug.Log(manager.IsShow);
        SoundCon.instance.PlaySound(1);
        
    }

    private IEnumerator loadNextScene(){
        yield return new WaitForSeconds(1f);
    }
}
